package org.edu.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Proxy;

@Entity
@Proxy(lazy = false)
@Table(name = "TEACHERLESSON", catalog = "SCHOOL")
public class TeacherLesson implements Serializable {

	private static final long serialVersionUID = 1L;
	private Long teacher_lesson_id;
	private Teacher teacher;
	private Lesson lesson;
	private SemesterNotes semesterNotes;
	private Set<StudentLesson> studentLessons = new HashSet<>();

	@Id
	@GeneratedValue
	@Column(name = "TEACHER_LESSON_ID")
	public Long getTeacher_lesson_id() {
		return teacher_lesson_id;
	}

	public void setTeacher_lesson_id(Long teacher_lesson_id) {
		this.teacher_lesson_id = teacher_lesson_id;
	}

	@ManyToOne
	@JoinColumn(name = "TEACHER_ID")
	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	@ManyToOne
	@JoinColumn(name = "LESSON_ID")
	public Lesson getLesson() {
		return lesson;
	}

	public void setLesson(Lesson lesson) {
		this.lesson = lesson;
	}

	@ManyToOne
	@JoinColumn(name = "SEMESTER_NOTES_ID")
	public SemesterNotes getSemesterNotes() {
		return semesterNotes;
	}

	public void setSemesterNotes(SemesterNotes semesterNotes) {
		this.semesterNotes = semesterNotes;
	}
	
	@OneToMany(targetEntity = StudentLesson.class, mappedBy = "teacherLesson", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@LazyCollection(LazyCollectionOption.FALSE)
	public Set<StudentLesson> getStudentLessons() {
		return studentLessons;
	}

	public void setStudentLessons(Set<StudentLesson> studentLessons) {
		this.studentLessons = studentLessons;
	}

	public TeacherLesson() {
		super();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime
				* result
				+ ((teacher_lesson_id == null) ? 0 : teacher_lesson_id
						.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TeacherLesson other = (TeacherLesson) obj;
		if (teacher_lesson_id == null) {
			if (other.teacher_lesson_id != null)
				return false;
		} else if (!teacher_lesson_id.equals(other.teacher_lesson_id))
			return false;
		return true;
	}	
}
